#pragma once

#include <QObject>
#include <osg\Vec3>
#include "attachobjecteffect.h"
#include <osg\ref_ptr>
#include "port3dapi_global.h"

namespace PublicGui
{
	class PerspectiveView;
}

namespace VrDataCore
{
	class ActorBase;
	class EffectCenter;
}

class ObjectEntitiesArray;
class DynamicDataCacheManager;
class ObjectEntities;
class DoubleArray;
class PositionArray;

class PORT3DAPI_EXPORT ActivexView:public QObject
{
	Q_OBJECT
public:
	ActivexView();
	~ActivexView();

	QWidget* getGLWidget();
	struct ScanParameter
	{
		osg::Vec3			_eye;
		osg::Vec3			_center;
		osg::Vec3			_up;
		int					_distance;
		int					_speed;
		QString				_mode;
		bool				_isInit;
	};
	bool openMap(const QString& mapname);
	bool haveOpenMap();
	bool closeMap();
	void setLookAt(const osg::Vec3& eye,const osg::Vec3& center,const osg::Vec3& up);
	void setLookAt(const QString& id,int offsetxy,int offsetxz,int distance);
	void getLookAt(float& eyex,float& eyey,float& eyez,float& centerx,float& centery,
										float& centerz,float& upx,float& upy,float& upz,float& distance);
	bool followObject(const QString& id,double centeroffsetx,double centeroffsety,double centeroffsetz,int distance,int anglexy, int anglexz);
	void moveCenterTo(double x,double y);
	void zoom(double ratio);
	void markObject(const QString& ids,const QString& texts,int type,int r,int g,int b,int scal);
	void unMarkObject(const QString& ids);
	void updateObjectsMotion(ObjectEntitiesArray* entitiesarray);
	bool deleteObject(const QString& id);
	void setPropertyWindowParameter(int windowwidth,int windowheight,double namewidth,double valuewidth,
		int nametextsize,int valuetextsize,const osg::Vec3& nametextcolor,const osg::Vec3& valuetextcolor);
	bool createAutoMoveObjectWithTrack(ObjectEntities* entities, PositionArray* p,DoubleArray* t,bool loop);
	bool createAutoUniformMoveObjectWithTrack(ObjectEntities* entities, PositionArray* p,double speed,bool loop);
	void createOrUpdateObjects_2(const QString& shipid,const QString& mmsi,const QString& imo,const QString& type,
		const QString& name,double lng,double lat,const QString& callsign,double beam,const QString& cargotype,
		const QString& country,double course,const QString& dest,double draught,const QString& eta,double heading,
		double lasttime,double left,double length,double rot,double speed,const QString& status,double trail);
	void createOrUpdateObjects_3(const QStringList& datalist);
	void showPropertyWidget(ObjectEntities* entities);
	void hidePropertyWidget();
	void initHudToolbar();
	void setToolTip(const QString& text);
	void setToolTipParameter(int textsize,int textr,int textg,int textb,int backgroundr,
		int backgroundg,int backgroundb,int backgrounda);
	void makeObjectColorBlink(const QString& ids,int totaltime,int intterval,int r,int g,int b,int a);
	void stopObjectColorBlink(const QString& ids);
	void makeObjectBlink(const QString& ids,int totaltime,int intterval);
	void stopObjectBlink(const QString& ids);
	void updateCommondShape(const QString& id,int type,const osg::Vec4& color,float radious,float heightpercent
		,float totalheight,bool autosize,bool canbeblock);
	void clearCommondShape();
	void addTabsInteractionWindow(const QString& title,const osg::Vec3& color);
	void removeTabsInteractionWindow(const QString& title);
	void addTextInteractionInformationWindow(const QString& text,const QString& title);
	void setScanParameterAt(int mode,const osg::Vec3& eye,const osg::Vec3& center,const osg::Vec3& up);
	void setScanMode(int mode);
	void setScanSpeed(int mode,int speed);
	void setObjectsValidStatus(const QStringList& idlist,const QStringList& statuslist);
	bool showObject(const QString& id,bool state);
	bool showObjects(QVector<QString> ids,bool state);
	bool showTarget(int type, int subtype,bool state);
	void showRemarkLayer(const QStringList& remarknamelist);
	void hideRemarkLayer(const QStringList& remarknamelist);
	void showArea(const QStringList& areanamelist);
	void hideArea(const QStringList& areanamelist);
	void addToolBarButton(int buttonType);
	void setToolBarActive(int type,bool active);
	void addRemarkedAt(const QString& remarklayername,const QString& text,double x,double y,double z);
	void removeRemark(const QString& remarklayername,const QString& text);
	void addAdvancedToolBarButton(int type,const QString& buttonname,const QString& buttonicon,const QString& buttoniconeffect);
	QString getAllPlayCameraAnimationName();
	void playCameraAnimation(const QString& name);
	void showGuideMapWindow();
	void hideGuideMapWindow();
private:
	void init();
	void resetToDefault();
	void connectSlots();
	void defineDefaultCameraParameter();
	void addScanParameterAt(const osg::Vec3& eye,const osg::Vec3& center,const osg::Vec3& up,const QString& mode);
	void toolButtonClick(std::string buttonname);
	void bubbleButtonClick(std::string buttonname);
	void addDefaultDrawable();
	void dynamicObjectCreate(osg::ref_ptr<CoreBase::ActorBase> p);
	void dynamicObjectDelete(osg::ref_ptr<CoreBase::ActorBase> p);
	void resetScan();
	PublicGui::PerspectiveView*								_perspectiveView;
	DynamicDataCacheManager*								_dynamicDataCacheManager;
	bool													_firstInit;
	osg::ref_ptr<ControlCenter::AttachObjectEffect>			_attachObjectEffect;
	CoreBase::ActorBase*									_attachObject;
	int														_hoverPointX;
	int														_hoverPointY;
	VrDataCore::EffectCenter*								_effectCenter;
	QVector<ScanParameter>									_modeToScanParameter;
	bool													_hideArea;
	bool													_loadMapSuccess;
	bool													_hideRemarkLayer;
private slots:
	void slotsMouseLeftClickEvent(const int,const int);
	void slotsMouseRightClickEvent(const int,const int);
	void slotsMouseDoubleClickEvent(const int,const int);
	void slotsHoverEvent(const int,const int);
	void viewResizeEvent(const int w,const int h);
	void slotsKeyPressEvent(const int,const int,const int);
signals:
	void signalsMouseLeftClickEvent(const int,const int,const double,const double,QString);
	void signalsMouseRightClickEvent(const int,const int,const double,const double,QString);
	void signalsMouseDoubleClickEvent(const int,const int,const double,const double,QString);
	void signalHoverEvent(const int,const int,const double,const double,QString);
	void signalsKeyPressEvent(const int,const int,const int,const double,const double);
	void signalsToolButtonClick(QString buttonname);
};